Repository navigation
fix(@angular/build): prevent missing NgModule scope errors in unit tests - #34287
Open
alan-agius4 wants to merge 2 commits into
Open
alan-agius4 wants to merge 2 commits into
alan-agius4 wants to merge 2 commits into
Conversation
Previously, `rootFiles` was used to restrict TypeScript compilation root names to only the test files to be executed. However, when an application `tsconfig.spec.json` includes application source files (standard for NgModule-based applications), non-standalone components rely on `AppModule` being present in the TypeScript program's root names for the Angular compiler to determine their compilation scope. Restricting root names caused template diagnostic errors such as `NG8001: '<element>' is not a known element`. This change replaces the root file allowlisting in the unit-test runner with an `excludeRootFiles` option that excludes unselected test files from the compilation roots. This ensures application files and NgModule definitions remain in the program while still ignoring unselected test files with compilation errors. Closes angular#34231
There was a problem hiding this comment.
Code Review
This pull request replaces the rootFiles option with excludeRootFiles across the Angular build pipeline to exclude unselected test files from the TypeScript compilation root names rather than restricting them. It also adds unit tests to verify that NgModule declared components compile correctly when using include or when tsConfig includes application files. Feedback suggests optimizing getVitestBuildOptions by avoiding a redundant and potentially expensive second glob scan of the workspace when running the full test suite with default test patterns and no exclusions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously,
rootFileswas used to restrict TypeScript compilation root names to only the test files to be executed. However, when an applicationtsconfig.spec.jsonincludes application source files (standard for NgModule-based applications), non-standalone components rely onAppModulebeing present in the TypeScript program's root names for the Angular compiler to determine their compilation scope. Restricting root names caused template diagnostic errors such asNG8001: '<element>' is not a known element.This change replaces the root file allowlisting in the unit-test runner with an
excludeRootFilesoption that excludes unselected test files from the compilation roots. This ensures application files and NgModule definitions remain in the program while still ignoring unselected test files with compilation errors.Closes #34231